<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">初始密码</label>
                    <div class="layui-input-block">
                        <input type="text" name="password"  autocomplete="off" placeholder="请输入初始密码" class="layui-input" lay-verify="pass">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="text"  name="newPassword" lay-verify="pass" autocomplete="off" placeholder="请输入新密码" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="role-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
layui.use(['form','jquery','select'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    let select = layui.select;
    let userId;
    //表单校验规则
    form.verify({
        pass: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]
    });
    form.on('submit(role-save)', function(data){
        data.field.userId = userId
        $.ajax({
            url:'/user/pass-edit',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(){
                layer.msg('密码修改成功,请重新登录！',{icon:1,time:2000},function(){
                    //parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    parent.window.lgoutAndRefresh();
                });
            },
            error: function (data) {
                layer.msg(data.responseJSON.detail,{icon:2,time:1000});
            }
        })
        return false;
    });
    window.init = function (obj) {
        userId = obj;
    };
})
</script>
</body>
</html>
